package com.shen.thread.demo1;


import java.util.concurrent.*;

public class threadCall implements Callable<Boolean> {
    private String url;//图片地址
    private String name;//文件名

    public threadCall(String url, String name) {
        this.url = url;
        this.name = name;
    }

    @Override
    public Boolean call() {
        WebDownLoading webDownLoader = new WebDownLoading();
        webDownLoader.downloader(url, name);
        System.out.println("下载文名" + name);
        return true;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        threadCall t1 = new threadCall("https://bkimg.cdn.bcebos.com/pic/b8014a90f603738da97755563251a751f81986184626?x-bce-process=image/resize,m_lfit,w_268,limit_1/format,f_jpg", "1.jpg");
        threadCall t2 = new threadCall("https://bkimg.cdn.bcebos.com/pic/b8014a90f603738da97755563251a751f81986184626?x-bce-process=image/resize,m_lfit,w_268,limit_1/format,f_jpg", "2.jpg");
        //创建执行服务
        ExecutorService ser = Executors.newFixedThreadPool(2);
        //提交执行
        Future<Boolean> r1 = ser.submit(t1);
        Future<Boolean> r2 = ser.submit(t2);
        //获取结果
        Boolean rs1 = r1.get();
        Boolean rs2 = r2.get();

        ser.shutdownNow();

    }
}


